package com.ss.android.common.util;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;

public final class AnimatorUtil {
    private static final Interpolator sInterpolator = new DecelerateInterpolator();

    public static void animateTopSlideIn(final View view) {
        if (view != null) {
            if (view.getVisibility() != View.VISIBLE && view.getAlpha() != 0f) {
                view.setAlpha(0f);
                view.setTranslationY(((float) (-view.getHeight())));
            }

            view
                    .animate()
                    .alpha(1f)
                    .translationY(0f)
                    .setDuration(360)
                    .setInterpolator(sInterpolator)
                    .setListener(new AnimatorListenerAdapter() {
                        public final void onAnimationStart(Animator animator) {
                            view.setVisibility(View.VISIBLE);
                        }
                    })
                    .start();
        }
    }

    public static void animateTopSlideOut(final View view) {
        view
                .animate()
                .alpha(0f)
                .translationY(((float) (-view.getHeight())))
                .setDuration(360)
                .setInterpolator(sInterpolator)
                .setListener(new AnimatorListenerAdapter() {
                    public final void onAnimationEnd(Animator animator) {
                        view.setVisibility(View.INVISIBLE);
                    }
                })
                .start();
    }
}

